using System;
using System.Windows;

using EMan.Common.DependencyInjection;
using EMan.Interface.Common;
using EMan.Interface.EntityEditing;

using TrueCode.Core;
using TrueCode.Core.Aspects;

namespace EMan.GUI.Common.EntityEditing
{
  public class BaseEntityEditorView< TPresenter, TView > : BaseViewUserControl< TPresenter, TView >, IEntityEditorView,
                                                    IEntityEditorGuiElement
    where TPresenter : class, IEntityEditorPresenter, IPresenter< TView > where TView : IView
  {
    #region .ctors
    protected BaseEntityEditorView( [NotNull] IFactory factory, [NotNull] TPresenter presenter ) : base( factory, presenter ){}
    #endregion

    #region Implementation of IEntityEditorView
    public void Close()
    {
      Closed.Raise( this );
    }

    public event EventHandler Closed;

    public FrameworkElement Control
    {
      get { return this; }
    }
    #endregion

    public bool Submitted{ get; set; }

    #region Implementation of IEntityEditorGuiElement
    public void AskToClose()
    {
      Presenter.CancelCommand.Execute(null);
    }
    #endregion

    #region WPF
    // It is for visual control designer
    [UsedImplicitly]
    protected BaseEntityEditorView()
    {
    }
    #endregion
  }

  public class BaseEntityEditorView< TPresenter > : BaseEntityEditorView< TPresenter, IEntityEditorView > where TPresenter : class, IEntityEditorPresenter, IPresenter< IEntityEditorView >
  {
    protected BaseEntityEditorView( [NotNull] IFactory factory, [NotNull] TPresenter presenter ) : base( factory, presenter ){}

    #region WPF
    // It is for visual control designer
    [UsedImplicitly]
    protected BaseEntityEditorView()
    {
    }
    #endregion
  }
}